﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CetWin.Phone.Entity;
using System.Collections.ObjectModel;
using Phone.Framework;
using System.Linq;
using Caliburn.Micro;
using PF = Phone.Framework;
using CetWin.Phone.Services;
using Microsoft.Phone.Controls;
namespace CetWin.ViewModels
{
    public class CategoryViewModel : PF.PropertyChangedBase
    {
        private readonly INavigationService navigationService;
        private readonly CategoryService _categoryService;
        public CategoryViewModel(INavigationService navigationService)
        {
            this.navigationService = navigationService;
            _categoryService = IoC.Get<CategoryService>();

            NormalCategories = new ObservableCollection<Category>(_categoryService.GetNormalCategory());
            DateCategories = new ObservableCollection<Category>(_categoryService.GetDateCategory());
        }

        private void NavigatetoSaveCategoryView()
        {
            navigationService.UriFor<SaveCategoryViewModel>().Navigate();
        }

        public void ChangePivot()
        {
          
        }

        public void ShowCategoryWord(ExpanderView view)
        {
            var header = view.Header as Category;
            if (header.Words == null)
                header.Words = _categoryService.GetCategoryWord(header);
          
        }

        public void AddCategory()
        {
            NavigatetoSaveCategoryView();
        }

        private Category _selectedItem;

        public Category SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                _selectedItem = value;
                NotifyPropertyChanged("SelectedItem");
                if (value != null)
                {
                    PhoneStateManager.SetAppState(GlobalConstant.SelectedCategorydField, SelectedItem);
                    NavigatetoSaveCategoryView();
                }
            }
        }

        private ObservableCollection<Category> _normalCategories;

        public ObservableCollection<Category> NormalCategories
        {
            get { return _normalCategories; }
            set
            {
                _normalCategories = value;
                NotifyPropertyChanged("NormalCategories");
            }
        }

        private ObservableCollection<Category> _dateCategories;

        public ObservableCollection<Category> DateCategories
        {
            get { return _dateCategories; }
            set
            {
                _dateCategories = value;
                NotifyPropertyChanged("DateCategories");
            }
        }

    }
}
